from sblab.models import ExpDesign, ExpVariables, FilingOrder, Projects, ProjectSamples, Samples, Contacts
from django import forms
from django.db import models
from django.contrib import admin

""" -------------------------------[ inlines ]----------------------------------
These objects will be showed in the parent table
"""

class ExpDesignInline(admin.TabularInline):
    model = ExpDesign

" --------------------------[ ModelAdmin ]------------------------------------ "

class FilingOrderAdmin(admin.ModelAdmin):
    list_display= ['table_name', 'filing_order']
    ordering= ('filing_order',)
    formfield_overrides = {
        models.CharField:    {'widget': forms.TextInput(attrs={'size':'20'})},        
    }

class ContactsAdmin(admin.ModelAdmin):
    list_display= ['contact_name']
    ordering= ('contact_name',)

class ProjectsAdmin(admin.ModelAdmin):
    list_display= ['project', 'start_date', 'contact', 'notes']
    ordering= ('project',)

class SamplesAdmin(admin.ModelAdmin):
    list_display= ['sample_id', 'sample_owner', 'notes']
    ordering= ('sample_owner','sample_id',)
    inlines= [ExpDesignInline, ]
    search_fields= ['sample_id', 'notes'] ##, 'sample_owner', 'notes']
    
class ProjectSamplesAdmin(admin.ModelAdmin):
    list_display= ['id', 'project', 'sample']
    ordering= ('project', 'sample', )

class ExpVariablesAdmin(admin.ModelAdmin):
    list_display= ['s_variable', 'description']
    ordering= ('s_variable', 'description',)
    
class ExpDesignAdmin(admin.ModelAdmin):
    list_display= ['sample', 's_variable', 's_value']
    ordering= ('sample', 's_variable', 's_value',)
    


admin.site.register(FilingOrder, FilingOrderAdmin)
admin.site.register(Projects, ProjectsAdmin)
admin.site.register(Contacts, ContactsAdmin)
admin.site.register(ProjectSamples, ProjectSamplesAdmin)
admin.site.register(Samples, SamplesAdmin)
admin.site.register(ExpVariables, ExpVariablesAdmin)
admin.site.register(ExpDesign, ExpDesignAdmin)
